package br.com.ecomm.model.dao.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import br.com.ecomm.model.dao.LoginDAO;
import br.com.ecomm.model.entity.Login;
import br.com.ecomm.util.jdbc.ConnectionJDBCFactory;
import br.com.ecomm.util.jdbc.ConnectionJDBCFactory.TypesConnections;


public class LoginDAOImpl implements LoginDAO{
	
	private Connection conn;
	
	public LoginDAOImpl(){
		conn = ConnectionJDBCFactory.getConnection(TypesConnections.MySQL_CONNECTION);
	}
	
	@Override
	public boolean valida(Login login) {
		try {
			PreparedStatement pStmt = conn.prepareStatement("select * from ACCOUNT where USERNAME = ? and PASSWORD = ?");
			pStmt.setString(1, login.getUsuario());
			pStmt.setString(2, login.getSenha());
			ResultSet rs = pStmt.executeQuery();
			if (rs.next()) {
				return true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return false;
	}
}
